﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:Control="clr-namespace:WPNextTools.NControls"
                    xmlns:System="clr-namespace:System;assembly=mscorlib"
                    xmlns:vsm="clr-namespace:System.Windows;assembly=System.Windows">

    <Style x:Key="ExtendedScrollViewerStyle" TargetType="ScrollViewer">
        <Setter Property="VerticalScrollBarVisibility" Value="Auto" />
        <Setter Property="HorizontalScrollBarVisibility" Value="Disabled" />
        <Setter Property="Background" Value="Transparent" />
        <Setter Property="Padding" Value="0" />
        <Setter Property="BorderThickness" Value="0" />
        <Setter Property="BorderBrush" Value="Transparent" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="ScrollViewer">
                    <Border Background="{TemplateBinding Background}"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}">
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="ScrollStates">
                                <VisualStateGroup.Transitions>
                                    <VisualTransition GeneratedDuration="00:00:00.5" />
                                </VisualStateGroup.Transitions>
                                <VisualState x:Name="Scrolling">
                                    <Storyboard>
                                        <DoubleAnimation Duration="0"
                                                         Storyboard.TargetName="VerticalScrollBar"
                                                         Storyboard.TargetProperty="Opacity"
                                                         To="1" />
                                        <DoubleAnimation Duration="0"
                                                         Storyboard.TargetName="HorizontalScrollBar"
                                                         Storyboard.TargetProperty="Opacity"
                                                         To="1" />
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="NotScrolling" />
                            </VisualStateGroup>
                            <VisualStateGroup x:Name="VerticalCompression">
                                <VisualState x:Name="NoVerticalCompression" />
                                <VisualState x:Name="CompressionTop" />
                                <VisualState x:Name="CompressionBottom" />
                            </VisualStateGroup>
                            <VisualStateGroup x:Name="HorizontalCompression">
                                <VisualState x:Name="NoHorizontalCompression" />
                                <VisualState x:Name="CompressionLeft" />
                                <VisualState x:Name="CompressionRight" />
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>
                        <Grid Margin="{TemplateBinding Padding}">
                            <ScrollContentPresenter x:Name="ScrollContentPresenter"
                                                    Content="{TemplateBinding Content}"
                                                    ContentTemplate="{TemplateBinding ContentTemplate}" />
                            <ScrollBar x:Name="VerticalScrollBar"
                                       Width="5"
                                       Height="Auto"
                                       HorizontalAlignment="Right"
                                       VerticalAlignment="Stretch"
                                       IsHitTestVisible="False"
                                       IsTabStop="False"
                                       Maximum="{TemplateBinding ScrollableHeight}"
                                       Minimum="0"
                                       Opacity="0"
                                       Orientation="Vertical"
                                       ViewportSize="{TemplateBinding ViewportHeight}"
                                       Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}"
                                       Value="{TemplateBinding VerticalOffset}" />
                            <ScrollBar x:Name="HorizontalScrollBar"
                                       Width="Auto"
                                       Height="5"
                                       HorizontalAlignment="Stretch"
                                       VerticalAlignment="Bottom"
                                       IsHitTestVisible="False"
                                       IsTabStop="False"
                                       Maximum="{TemplateBinding ScrollableWidth}"
                                       Minimum="0"
                                       Opacity="0"
                                       Orientation="Horizontal"
                                       ViewportSize="{TemplateBinding ViewportWidth}"
                                       Visibility="{TemplateBinding ComputedHorizontalScrollBarVisibility}"
                                       Value="{TemplateBinding HorizontalOffset}" />
                        </Grid>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style TargetType="Control:PhotoListBox">
        <Setter Property="Background" Value="Transparent" />
        <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto" />
        <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Disabled" />
        <Setter Property="HeaderContentTemplate">
            <Setter.Value>
                <DataTemplate>
                    <TextBlock HorizontalAlignment="Center"
                               VerticalAlignment="Center"
                               Foreground="Black"
                               Text="{Binding}" />
                </DataTemplate>
            </Setter.Value>
        </Setter>
        <Setter Property="LoadingContentTemplate">
            <Setter.Value>
                <DataTemplate>
                    <TextBlock HorizontalAlignment="Center"
                               VerticalAlignment="Center"
                               Foreground="Black"
                               Text="{Binding}" />
                </DataTemplate>
            </Setter.Value>
        </Setter>
        <Setter Property="EmptyContentTemplate">
            <Setter.Value>
                <DataTemplate>
                    <TextBlock HorizontalAlignment="Center"
                               VerticalAlignment="Center"
                               FontSize="48"
                               Foreground="Black"
                               Text="{Binding}" />
                </DataTemplate>
            </Setter.Value>
        </Setter>
        <Setter Property="UnionHeaderContentTemplate">
            <Setter.Value>
                <DataTemplate>
                    <TextBlock HorizontalAlignment="Center"
                               VerticalAlignment="Center"
                               Foreground="Black"
                               Text="{Binding}" />
                </DataTemplate>
            </Setter.Value>
        </Setter>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="Control:PhotoListBox">
                    <Border Margin="0"
                            Background="{TemplateBinding Background}"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}">
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="CommonStates">
                                <VisualState x:Name="Normal">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PART_HeaderContentPresenter" Storyboard.TargetProperty="Visibility">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed" />
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PART_LoadingContentPresenter" Storyboard.TargetProperty="Visibility">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed" />
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PART_ManipulationContainer" Storyboard.TargetProperty="Visibility">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="Visible" />
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PART_EmptyContentPresenter" Storyboard.TargetProperty="Visibility">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed" />
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="PullToTop">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PART_HeaderContentPresenter" Storyboard.TargetProperty="Visibility">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="Visible" />
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PART_LoadingContentPresenter" Storyboard.TargetProperty="Visibility">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed" />
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PART_ManipulationContainer" Storyboard.TargetProperty="Visibility">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="Visible" />
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PART_EmptyContentPresenter" Storyboard.TargetProperty="Visibility">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed" />
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="PullToDown">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PART_HeaderContentPresenter" Storyboard.TargetProperty="Visibility">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed" />
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PART_LoadingContentPresenter" Storyboard.TargetProperty="Visibility">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="Visible" />
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PART_ManipulationContainer" Storyboard.TargetProperty="Visibility">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="Visible" />
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PART_EmptyContentPresenter" Storyboard.TargetProperty="Visibility">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed" />
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="NoData">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PART_HeaderContentPresenter" Storyboard.TargetProperty="Visibility">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed" />
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PART_LoadingContentPresenter" Storyboard.TargetProperty="Visibility">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed" />
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PART_ScrollableContent" Storyboard.TargetProperty="Visibility">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed" />
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PART_EmptyContentPresenter" Storyboard.TargetProperty="Visibility">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="Visible" />
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>
                        <Grid x:Name="LayoutRoot">
                            <Control:PullDownToRefreshPanel x:Name="PART_PullDownRefreshPanel" />
                            <!--  放在此处，当有header 时不能用刷新功能  -->
                            <ScrollViewer x:Name="PART_ManipulationContainer" Style="{StaticResource ExtendedScrollViewerStyle}">
                                <StackPanel x:Name="PART_MainContainer">
                                    <ContentPresenter x:Name="PART_HeaderContentPresenter"
                                                      HorizontalAlignment="Stretch"
                                                      VerticalAlignment="Stretch"
                                                      Content="{TemplateBinding HeaderContent}"
                                                      ContentTemplate="{TemplateBinding HeaderContentTemplate}"
                                                      Visibility="Collapsed" />
                                    <ContentPresenter x:Name="PART_UnionHeaderPresenter"
                                                      HorizontalAlignment="Stretch"
                                                      VerticalAlignment="Stretch"
                                                      Content="{TemplateBinding UnionHeaderContent}"
                                                      ContentTemplate="{TemplateBinding UnionHeaderContentTemplate}"
                                                      Visibility="Collapsed" />

                                    <Canvas x:Name="PART_ScrollableContent">
                                        <Canvas x:Name="PART_ItemsPanel" VerticalAlignment="Top" />
                                    </Canvas>
                                    <ContentPresenter x:Name="PART_LoadingContentPresenter"
                                                      HorizontalAlignment="Stretch"
                                                      VerticalAlignment="Stretch"
                                                      Content="{TemplateBinding LoadingContent}"
                                                      ContentTemplate="{TemplateBinding LoadingContentTemplate}"
                                                      Visibility="Collapsed" />
                                </StackPanel>
                            </ScrollViewer>
                            <ContentPresenter x:Name="PART_EmptyContentPresenter"
                                              HorizontalAlignment="Stretch"
                                              VerticalAlignment="Stretch"
                                              Content="{TemplateBinding EmptyContent}"
                                              ContentTemplate="{TemplateBinding EmptyContentTemplate}"
                                              Visibility="Collapsed" />
                        </Grid>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style TargetType="Control:PhotoListBoxItem">
        <Setter Property="Background" Value="Transparent" />
        <Setter Property="BorderThickness" Value="0" />
        <Setter Property="BorderBrush" Value="Transparent" />
        <Setter Property="Padding" Value="0" />
        <Setter Property="HorizontalContentAlignment" Value="Stretch" />
        <Setter Property="VerticalContentAlignment" Value="Stretch" />
        <Setter Property="CacheMode" Value="BitmapCache" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="Control:PhotoListBoxItem">
                    <Grid x:Name="PART_ContainerLayout"
                          HorizontalAlignment="Stretch"
                          VerticalAlignment="Stretch">
                        <ContentControl x:Name="PART_ContainerHolder"
                                        Margin="{TemplateBinding Margin}"
                                        HorizontalAlignment="Stretch"
                                        VerticalAlignment="Stretch"
                                        HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
                                        VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
                                        Content="{TemplateBinding Content}"
                                        ContentTemplate="{TemplateBinding ContentTemplate}" />
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>